#pragma once
#include<vector>
#include<iostream>
using namespace std;

class TreeNode
{
public:
	int val;
	TreeNode* left;
	TreeNode* right;
public:
	TreeNode(int v) :val(v), left(nullptr), right(nullptr) {}

};
class solution{
public:
	TreeNode* GenerateTree(vector<int>& vec)
	{
		if (vec.size() == 0)
		{
			return nullptr;
		}
		return process(vec, 0, vec.size() - 1);
	}
	TreeNode* process(vector<int>& vec, int l, int r)
	{
		if (l > r)
		{
			return nullptr;
		}
		int mid = l + ((r - l) >> 1);
		TreeNode* head = new TreeNode(vec[mid]);
		head->left = process(vec, l, mid - 1);
		head->right = process(vec, mid + 1, r);
		return head;
	}

	void preOrder(TreeNode* head)
	{
		if (head == nullptr)
		{
			return;
		}
		myprocess(head);
	}
	void myprocess(TreeNode* head)
	{
		if (head == nullptr)
		{
			return;
		}
		cout << head->val << "  ";
		myprocess(head->left);
		myprocess(head->right);
	}
};